<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
    <meta charset="UTF-8">
    <title layout:title-pattern="药品管理系统"></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.9.1/font/bootstrap-icons.css">
</head>
<body class="bg-light">
<!-- 响应式导航栏 -->
<nav class="navbar navbar-expand-lg navbar-dark bg-primary mb-4">
    <div class="container">
        <a class="navbar-brand" th:href="@{/}">药品管理系统</a>
        <button class="navbar-toggler" type="button"
                data-bs-toggle="collapse" data-bs-target="#navbarNav">
            <span class="navbar-toggler-icon"></span>
        </button>

        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav me-auto">
                <div class="navbar-nav me-auto" th:if="${session.user.hasRole(1)}">
                    <li class="nav-item">
                        <form th:action="@{/api/drugs}" method="get" th:if="${session.user.hasPermission(8)}">
                            <button type="submit" class="btn btn-link nav-link">药品列表</button>
                        </form>
                    </li>
                    <li class="nav-item">
                        <form th:action="@{/api/notices}" method="get" th:if="${session.user.hasPermission(4)}">
                            <button type="submit" class="btn btn-link nav-link">系统通知</button>
                        </form>
                    </li>
                    <li class="nav-item">
                        <form th:action="@{/api/user/log}" method="post" th:if="${session.user.hasPermission(2)}">
                            <button type="submit" class="btn btn-link nav-link">登录日志</button>
                        </form>
                    </li>
                    <li class="nav-item">
                        <form th:action="@{/api/permission}" method="get" th:if="${session.user.hasPermission(1)}">
                            <button type="submit" class="btn btn-link nav-link">权限管理</button>
                        </form>
                    </li>
                </div>
            </ul>

            <!-- 用户登录状态 -->
            <div class="d-flex align-items-center gap-3">
                <!-- 登录状态 -->
                <div th:if="${session.user}" class="dropdown">
                    <!-- 用户头像/名称区域 -->
                    <a class="btn btn-link text-decoration-none p-0 dropdown-toggle d-flex align-items-center"
                       href="#"
                       role="button"
                       data-bs-toggle="dropdown"
                       aria-expanded="false"
                       style="transition: all 0.3s ease;">
                        <!-- 头像显示优化 -->
                        <div class="position-relative">
                <span th:if="${session.avatar} == null"
                      class="bg-primary text-white rounded-circle d-flex align-items-center justify-content-center"
                      style="width: 40px; height: 40px; font-size: 0.9rem"
                      th:text="${session.user.username.substring(0,1).toUpperCase()}"></span>
                            <img th:if="${session.avatar} != null"
                                 th:src="@{'data:image/jpeg;base64,' + ${session.avatar}}"
                                 class="rounded-circle object-fit-cover shadow-sm"
                                 style="width: 40px; height: 40px; border: 2px solid #fff;">
                        </div>
                    </a>

                    <!-- 下拉菜单美化 -->
                    <ul class="dropdown-menu dropdown-menu-end shadow border-0 mt-2"
                        style="min-width: 180px; border-radius: 12px;">
                        <li>
                            <form th:action="@{/api/real_name_auth}" method="get">
                                <button type="submit"
                                        class="dropdown-item d-flex align-items-center py-2 px-3"
                                        style="font-size: 0.9rem; transition: background 0.2s;">
                                    <i class="fas fa-id-card me-2 opacity-75"></i>
                                    实名信息
                                </button>
                            </form>
                        </li>
                        <li><hr class="dropdown-divider my-1"></li>
                        <li>
                            <form th:action="@{/api/user/logout}" method="post">
                                <button type="submit"
                                        class="dropdown-item d-flex align-items-center py-2 px-3 text-danger"
                                        style="font-size: 0.9rem; transition: background 0.2s;">
                                    <i class="fas fa-sign-out-alt me-2 opacity-75"></i>
                                    退出登录
                                </button>
                            </form>
                        </li>
                    </ul>
                </div>

                <!-- 未登录状态 -->
                <a th:unless="${session.user}"
                   th:href="@{/api/user/login}"
                   class="btn btn-outline-light px-4 py-2 rounded-pill shadow-sm"
                   style="transition: all 0.3s ease; border-width: 1.5px;">
                    <i class="fas fa-sign-in-alt me-2"></i>
                    登录
                </a>
            </div>
        </div>
    </div>
</nav>

<!-- 内容区域 -->
<div class="container" layout:fragment="content">
    <!-- 页面具体内容将插入此处 -->
    <script layout:fragment="script"></script>
</div>

<!-- 公共脚本 -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/2.1.3/jquery.min.js"></script>
</body>
</html>